Sample Code
The XREAL SDK includes numerous sample scenes and code examples to help you understand and implement AR features in your applications. These samples demonstrate the capabilities of the SDK and provide reference implementations for various functionalities.
Sample Code Organization​
In the XREAL SDK plugin, sample code is provided in two forms:
- Demo Unity scenes that you can run directly
- C# script implementations that you can reference in your own code
The samples are organized into several categories in the plugin structure:
Interaction Basics​
Examples for input handling and interaction with virtual objects.
Feature | Unity Scene | Sample Code |
---|---|---|
Controller Basics | HelloMR | HelloMR |
Display Stability Optimization | FocusPlane | FocusPlanePanel |
Render Metrics | Metrics | MetricsPanel |
RayLaser | XREALLaser | XREALLaserReticle XREALLaserVisual |
StereoVideo | StereoVideo | StereoVideoDemo |
AR Features​
Examples demonstrating core AR capabilities such as tracking, detection, and meshing.
Feature | Unity Scene | Sample Code |
---|---|---|
Image Tracking | BasicImageTracking | TrackedImageInfoManager |
Plane Detection | PlaneDetection | ARFeatheredPlaneMeshVisualizer |
Mesh Classification | MeshClassification | MeshClassificationFracking |
Basic Meshing | NormalMesh | MeshSaver MeshSaveUtility MeshBlockInfo MeshChangeStateInfo |
Spatial Anchor | Anchors | Anchors.5(For ARF 5.0) Anchors.6(For ARF 6.0) AnchorInfo ConfirmDialog MapQualityBar MapQualityIndicator |
RGBCamera | RGBCamera | ARFoundationCameraSample |
Camera Features​
Examples for accessing and utilizing the RGB camera.
Feature | Unity Scene | Sample Code |
---|---|---|
Video Recording & Photo Capture | RGBCameraAndCapture | CaptureExample |
Accessing RGB Camera Data | RGBCameraAndCapture | RGBCameraExample |
First Person View | FirstPersonViewStreamingCast | FirstPersonStreammingCast |
Other Examples​
Additional demos and experimental features.
Feature | Unity Scene | Sample Code |
---|---|---|
XREAL Marker | MarkerTracking | MarkerImageExampleController |
Accessing the Sample Code​
To access these sample projects in your Unity environment:
-
Open your Unity project
-
Go to Window > Package Manager
-
Find and select XREAL XR Plugin from the package list
-
Navigate to the Samples tab
-
Click the Import button next to any sample you want to use in your project
You can import individual samples based on the specific feature you want to implement, or import all samples to explore the full range of XREAL SDK capabilities.
Using the Sample Code​
To use these samples:
- Open the XREAL SDK in Unity
- Navigate to the relevant scene in the project panel
- Run the scene to see the feature in action
- Review the attached scripts to understand the implementation Each sample demonstrates a specific feature or capability of the XREAL SDK and can serve as a starting point for implementing similar functionality in your own applications. For detailed information on specific features, refer to the corresponding documentation sections linked in the table above.